package com.yc.dao;

import com.yc.bean.UserBean;
import com.yc.commons.DBHelper;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

public class UserDao {
   static DBHelper db=new DBHelper();

    public static List<UserBean> find(String username,String pwd) {
        String sql="select * from tb_user where username=? and pwd=? and disabled=0";
        try {
            return db.select(UserBean.class,sql,username,pwd);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }

    public static int insert(String nickname,String username,String pwd) {
        String sql = "INSERT INTO tb_user (nickname, username, pwd, create_date, disabled) VALUES (?, ?, ?, NOW(), 0)";
        return db.doUpdate(sql, nickname, username, pwd);
    }

    public static List<UserBean> find() {
        String sql="select * from tb_user where  disabled=0";
        try {
            return db.select(UserBean.class,sql);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}
